package com.stropheware.droidDefense;

import com.stropheware.droidDefense.R;

import android.app.Activity;
import android.media.MediaPlayer;
import java.util.ArrayList;
import java.util.ListIterator;

public class GameAudioManager {
	
	private ArrayList<GameAudio> audioFileList;
	
	public GameAudioManager(Activity baseActivity) {
		audioFileList = new ArrayList<GameAudio>();
	}
	
	public void addGameAudio(GameAudio gameAudio) {
		audioFileList.add(gameAudio);
	}
	
	public int numAudio() {
		return audioFileList.size();
	}
	
	public GameAudio getByIndex(int index) {
		return audioFileList.get(index);
	}
	
	public void playAudio(String audioName) {
		ListIterator<GameAudio> iterator = (ListIterator<GameAudio>)audioFileList.listIterator();
		while(iterator.hasNext()) {
			GameAudio temp = (GameAudio)iterator.next();
			MediaPlayer tempMP= temp.getMediaPlayer();
			if(tempMP != null && temp.getName().equals(audioName)) {
				tempMP.start();
			}
		}
	}
	
	public void pauseAudio(String audioName) {
		ListIterator<GameAudio> iterator = (ListIterator<GameAudio>)audioFileList.listIterator();
		while(iterator.hasNext()) {
			GameAudio temp = (GameAudio)iterator.next();
			MediaPlayer tempMP= temp.getMediaPlayer();
			if(tempMP != null && temp.getName().equals(audioName)) {
				tempMP.pause();
			}
		}
	}

	
	public void pauseAllAudio() {
		ListIterator<GameAudio> iterator = (ListIterator<GameAudio>)audioFileList.listIterator();
		while(iterator.hasNext()) {
			MediaPlayer temp = ((GameAudio)iterator.next()).getMediaPlayer();
			if(temp != null) {
				temp.pause();
			}
		}
	}
	
	public void playAllAudio() {
		ListIterator<GameAudio> iterator = (ListIterator<GameAudio>)audioFileList.listIterator();
		while(iterator.hasNext()) {
			MediaPlayer temp = ((GameAudio)iterator.next()).getMediaPlayer();
			if(temp != null) {
				temp.start();
			}
		}
	}
	
}
